using System;
using System.Collections.Generic;

using IBatisNet.DataMapper;

using log4net;

using GymManager.Exception;
using GymManager.Persistence.VO;

namespace GymManager.Persistence.DAO
{
    /// <summary>
    /// Class responsible by getting information from database about student modality
    /// </summary>
    public class StudentModalityDAO
    {
        // logger instance
        private ILog _logManager = LogManager.GetLogger(typeof(StudentModalityDAO));

        /// <summary>
        /// Method responsible by getting all modalities beloging to an specific student
        /// </summary>
        /// <param name="Int32">student identifier</param>
        /// <returns>IList - list of modalities belonging to an specific student</returns>
        /// <see cref="GymManager.Exception.Persistence"/>
        public IList<StudentModality> findByStudent(Int32 studentId)
        {
            if (_logManager.IsInfoEnabled)
            {
                _logManager.Info("Begin Method");
            }

            // list to be returned
            IList<StudentModality> studentModalityList = null;

            try
            {
                ISqlMapper ibatisMapper = DAOManager.getInstance();
                studentModalityList = ibatisMapper.QueryForList<StudentModality>("StudentModality.findByStudent", studentId);
            }
            catch (System.Exception ex)
            {
                _logManager.Error("Error while retrieving student modality information", ex);
                throw new PersistenceException("Error while retrieving student modality information", ex);
            }

            if (_logManager.IsInfoEnabled)
            {
                _logManager.Info("End Method");
            }

            return studentModalityList;
        }

        /// <summary>
        /// Method responsible by getting the monthly fee associated to some student
        /// </summary>
        /// <param name="Int32">student identifier</param>
        /// <returns>Total Price</returns>
        /// <see cref="GymManager.Exception.PersistenceException"/>
        public Double getStudentMonthlyFee(Int32 studentId)
        {
            if (_logManager.IsInfoEnabled)
            {
                _logManager.Info("Begin Method");
            }

            Double studentMonthlyFee = 0;

            try
            {
                ISqlMapper ibatisMapper = DAOManager.getInstance();
                studentMonthlyFee = ibatisMapper.QueryForObject<Double>("StudentModality.getStudentMonthlyFee", studentId);
            }
            catch (System.Exception ex)
            {
                _logManager.Error("Error while retrieving student modality information", ex);
                throw new PersistenceException("Error while retrieving student modality information", ex);
            }

            if (_logManager.IsInfoEnabled)
            {
                _logManager.Info("End Method");
            }

            return studentMonthlyFee;
        }
    }
}
